#include "Capsule.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "Box.h"
#include "Sprite.h"
#include "MainGame.h"
#include "GunWeapon.h"
#include "RSManager.h"

Capsule::Capsule(Box* box, BULLET_ID gunWeapon_id) : Object(box, Obj_DYNAMID)
{	
	_gunWeapon_id= gunWeapon_id;
}
void Capsule::init()
{
	_sprite = RSManager::getInstance()->getSprite(CAPSULES);
	_hits = 1;
	_isAlive = true;	
	_box->_size = _sprite->getRenderSize();
	_box->_v.x = 4;
	_box->_v.y = 0;
	AssignMove(_box);
	active = false;
}
void Capsule :: update()
{
	if(_hits < 0)
	{
		_isAlive=false;
		GunWeapon* gunWeapon=new GunWeapon
			(new Box(_box->_position,D3DXVECTOR2(48,30),D3DXVECTOR2(5,0)),_gunWeapon_id);
		gunWeapon->init();
		gl_MainGame->addWorldObject(gunWeapon);
		return;
	}
	if(gl_camera->getLeftSide() > this->_box->getLeft() - 50)
	{
		active = true; 				 	
	}
	if(!active)
	{
		_colBox->_size = gl_BOX_0_0_0->_size;
		_colBox->_v = gl_BOX_0_0_0->_v;
		_colBox->_position = gl_BOX_0_0_0->_position;
		return;
	}

	moveSinY(4); 
	if(_box->getRight() > gl_camera->getRightSide())
	{
		gl_MainGame->removeWorldObject(this); 			
	}
}
void Capsule::render()
{	
	Object::render();
	if(active)
		_sprite->Render(_box->_position);
}
Box* Capsule::getCollisionBox()
{
	if(!active)
	{
		_colBox->_size = gl_BOX_0_0_0->_size;
		_colBox->_v = gl_BOX_0_0_0->_v;
		_colBox->_position = gl_BOX_0_0_0->_position;

	}
	else
	{
		_colBox->_position = _box->_position;
		_colBox->_size = _box->_size;
		_colBox->_v = _box->_v;
	}

	return _colBox;
}
Capsule::~Capsule(void)
{
}
